package com.ruoyi.yyq.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.annotation.InnerAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.yyq.domain.CarServiceDetails;
import com.ruoyi.yyq.service.ICarServiceDetailsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 服务详情Controller
 * 
 * @author ruoyi
 * @date 2025-05-10
 */
@RestController
@RequestMapping("/fuwudetails")
@CrossOrigin
public class CarServiceDetailsController extends BaseController
{
    @Autowired
    private ICarServiceDetailsService carServiceDetailsService;
    /**
     * 暴露接口查询服务详情列表
     */
    @InnerAuth
    @GetMapping("/getlist")
    public TableDataInfo getlist(CarServiceDetails carServiceDetails)
    {

        List<CarServiceDetails> list = carServiceDetailsService.selectCarServiceDetailsList(carServiceDetails);
        return getDataTable(list);
    }

    /**
     * 查询服务详情列表
     */
    @RequiresPermissions("fuwu:fuwudetails:list")
    @GetMapping("/list")
    public TableDataInfo list(CarServiceDetails carServiceDetails)
    {
        startPage();
        List<CarServiceDetails> list = carServiceDetailsService.selectCarServiceDetailsList(carServiceDetails);
        return getDataTable(list);
    }


    /**
     * 导出服务详情列表
     */
    @RequiresPermissions("fuwu:fuwudetails:export")
    @Log(title = "服务详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarServiceDetails carServiceDetails)
    {
        List<CarServiceDetails> list = carServiceDetailsService.selectCarServiceDetailsList(carServiceDetails);
        ExcelUtil<CarServiceDetails> util = new ExcelUtil<CarServiceDetails>(CarServiceDetails.class);
        util.exportExcel(response, list, "服务详情数据");
    }

    /**
     * 获取服务详情详细信息
     */
    @RequiresPermissions("fuwu:fuwudetails:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carServiceDetailsService.selectCarServiceDetailsById(id));
    }

    /**
     * 新增服务详情
     */
    @RequiresPermissions("fuwu:fuwudetails:add")
    @Log(title = "服务详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarServiceDetails carServiceDetails)
    {
        return toAjax(carServiceDetailsService.insertCarServiceDetails(carServiceDetails));
    }

    /**
     * 修改服务详情
     */
    @RequiresPermissions("fuwu:fuwudetails:edit")
    @Log(title = "服务详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarServiceDetails carServiceDetails)
    {
        return toAjax(carServiceDetailsService.updateCarServiceDetails(carServiceDetails));
    }

    /**
     * 删除服务详情
     */
    @RequiresPermissions("fuwu:fuwudetails:remove")
    @Log(title = "服务详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carServiceDetailsService.deleteCarServiceDetailsByIds(ids));
    }

    /**
     * 根据商户ID和类型ID查询服务详情列表
     */
    @GetMapping("/byMerchantAndType")
    public TableDataInfo getByMerchantAndType(
            @RequestParam Long merchantId,
            @RequestParam Long typeId) {
        startPage();
        List<CarServiceDetails> list = carServiceDetailsService.selectByMerchantIdAndTypeId(merchantId, typeId);
        return getDataTable(list);
    }
}
